package org.mybatis.generator.internal.util;

import java.io.*;
import java.util.*;

/**
 * Created by admin on 16/11/11.
 */
public class PropertiesUtil {


    private static Properties props;
    private static String fileName;
    private final static String FILE_PATH = "src/main/resources/myGeneratorConfig.properties";

    private PropertiesUtil() {

    }

    private static void readProperties(String fileName) {
        try {
            props = new Properties();
            FileInputStream fis = new FileInputStream(fileName);
            props.load(fis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取某个属性
     */
    public static String getProperty(String key) {
        readProperties(FILE_PATH);
        return props.getProperty(key);
    }

    /**
     * 获取所有属性，返回一个map,不常用
     * 可以试试props.putAll(t)
     */
    public static Map getAllProperty() {
        readProperties(FILE_PATH);
        Map map = new HashMap();
        Enumeration enu = props.propertyNames();
        while (enu.hasMoreElements()) {
            String key = (String) enu.nextElement();
            String value = props.getProperty(key);
            map.put(key, value);
        }
        return map;
    }

}
